<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
</head>
<body>
<div id="app">
    <h2>用户登录</h2>
    <p>账号：<input type="text" v-model="account"></p>
    <p>密码：<input type="password" v-model="password"></p>
    <button @click="login">登录</button>
    <p v-if="errorMessage" style="color: red;">{{ errorMessage }}</p>
</div>

<script src="js/vue.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            account: '',
            password: '',
            errorMessage: ''
        },
        methods: {
            login() {
                this.errorMessage = '';

                axios.post('http://localhost:8080/login', {
                    account: this.account,
                    password: this.password
                })
                    .then(response => {
                        if (response.data.code === 200) {
                            // 登录成功，跳转到学生列表页面
                            window.location.href = 'AxiosDemo.html';
                        } else {
                            // 登录失败，显示错误信息
                            this.errorMessage = response.data.message;
                        }
                    })
                    .catch(error => {
                        // 处理请求错误，例如网络问题
                        this.errorMessage = '登录请求失败，请检查网络连接';
                        console.error(error);
                    });
            }
        }
    });
</script>
</body>
</html>